<?php

if (!class_exists('objectPage')) {
    require(CORE_INCLUDE_DIR.'/objectPage.php');
}
class admin_logistic extends objectPage{
    var $object = 'plugins/express_manager/logistic';
    var $finder_default_cols = 'logi_id';
    var $workground = 'order';
    //var $filterUnable = true;
    
    function admin_logistic(){
        
        parent::objectPage();
        $this->view_dir = dirname(__FILE__).'/view/admin';
        $this->finder_action_tpl = $this->view_dir.'/logistic/finder_action.html';
        //$this->finder_filter_tpl=$this->view_dir.'/logistic/finder_filter.html';
    }
    function export(){
        $this->template_dir = CORE_DIR.'/admin/view/';
        parent::export();
    }
    function colsetting(){
        $this->template_dir = CORE_DIR.'/admin/view/';
        parent::colsetting();
    }
    function detail($object_id,$func=null){
          $this->template_dir = CORE_DIR.'/admin/view/';
          parent::detail($object_id,$func=null);
    }
    function index(){
        $this->template_dir = CORE_DIR.'/admin/view/';
        parent::index();
    }

    function addNew(){
        $this->path[] = array('text'=>__('添加快件单信息'));
        $this->pagedata['status'] = array (
            'progress' => __('运送中'),
            'succ' => __('成功到达'),
            'failed' => __('发货失败'),
            'cancel' => __('已取消'),
            'lost' => __('货物丢失'),
            'timeout' => __('超时'),
            //'ready' => __('准备发货'),
        );
        $this->display('view/admin/logistic/addNew.html');
    }

    function edit($logi_id)
    {
        $objLogistic = &$this->system->loadModel($this->object);
        $row = $objLogistic->getFieldById($logi_id);
        $aItems = $objLogistic->getItemsByLogiId($logi_id);
        $this->pagedata['status'] = array (
            'succ' => __('成功到达'),
            'failed' => __('发货失败'),
            'cancel' => __('已取消'),
            'lost' => __('货物丢失'),
            'progress' => __('运送中'),
            'timeout' => __('超时'),
            //'ready' => __('准备发货'),
        );
        $this->pagedata['data'] = $row;
        $this->pagedata['items'] = $aItems;
        $this->display('view/admin/logistic/edit.html');
    }

    function save()
    {
        $this->filterVar($_POST);
        $this->template_dir = CORE_DIR.'/admin/view/';
        $this->begin('index.php?ctl=plugins/logistic&act=index');
        if (!$_POST['ship_tel'] && !$_POST['ship_mobile']) {
            $this->end(false,'请填写 电话 或 手机 其中至少一种联系方式！');
        }
        if (!$_POST['goods']) {
            $this->end(false,'请至少填写一项物品信息');
        }
        $data = $_POST;
        $data['uptime'] = time();
        if (!$data['logi_id']) {
            $data['createtime'] = $data['uptime'];
        }
        $data['op_user'] = $this->system->op_id;
        $objLogistic = &$this->system->loadModel($this->object);
        if (!$result = $objLogistic->save($data)) {
            $this->end(false,__('保存失败'));
        } else {
            $this->end(true,__('保存成功'));
        }
    }

    function filterVar(&$data)
    {
        if (is_array($data)) {
            foreach ($data as $k => $v) {
                $this->filterVar($data[$k]);
            }
        } else {
            $data = trim($data);
        }
    }
}

?>
